package com.example.test_event_and_callback.impl;

import com.example.test_event_and_callback.infras.async.AsyncExecuteProxy;
import com.example.test_event_and_callback.infras.event.CallableEventPublisher;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Song Dan Yang
 * Description: </br>
 * date: 2023/11/21 15:42
 */
@RestController
public class Controller {

    @Resource
    private CallableEventPublisher eventPublisher;

    @Resource
    private AsyncExecuteProxy asyncExecuteProxy;





    @RequestMapping("/test")
    public void testEvent(){


        TestAsyncDto result = null;
        long start = System.currentTimeMillis();
        try {
            for (int i = 0; i < 1; i++) {
                result = asyncExecuteProxy.execute(new TestAsyncDto(),"11");
//                TestDto testDto = asyncExecuteProxy.execute(new TestDto(),"11");
//                System.out.println(result);
//                System.out.println(testDto);
//                System.out.println(result);
            }
        } finally {
            System.out.println("cost time: " + (System.currentTimeMillis() - start) + " ms");
            System.out.println(result);
        }

        TestDto result1 = null;
        long start1 = System.currentTimeMillis();
        try {
            for (int i = 0; i < 1; i++) {
                result1 = asyncExecuteProxy.execute(new TestDto(),"11");
//                TestDto testDto = asyncExecuteProxy.execute(new TestDto(),"11");
//                System.out.println(result);
//                System.out.println(testDto);
//                System.out.println(result);
            }
        } finally {
            System.out.println("cost time: " + (System.currentTimeMillis() - start1) + " ms");
            System.out.println(result1);
        }
    }
}
